IF NOT EXISTS(SELECT * FROM sysobjects WHERE name='ONE_MTAB')      --判断表是否存在  
CREATE TABLE [dbo].[ONE_MTAB] (
[KEY_VALUE] varchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[ACT_TYPE] varchar(20) COLLATE Chinese_PRC_CI_AS NULL ,
[TAB_NAME] varchar(20) COLLATE Chinese_PRC_CI_AS NULL ,
[TIM_STAMP] timestamp NULL 
)

CREATE TRIGGER [dbo].[onemore_spjhd]
ON [dbo].[SPJHD]
AFTER INSERT, UPDATE, DELETE
AS
BEGIN
DECLARE
@strAction varchar(10)

IF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted)
BEGIN
	SET @strAction = 'insert'
END
 
IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
SET @strAction = 'update'
 
IF NOT EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
SET @strAction = 'delete'
declare @KEY_VALUE varchar(50);
IF @strAction = 'delete'
	select @KEY_VALUE=DJBH from deleted; 
ELSE
	select @KEY_VALUE=DJBH from inserted; 
insert into ONE_MTAB (KEY_VALUE,TAB_NAME,ACT_TYPE) values(@KEY_VALUE,'SPJHD',@strAction); 
END
GO
-----------------------------------------------------------
CREATE TRIGGER [dbo].[onemore_spthd]
ON [dbo].[SPTHD]
AFTER INSERT, UPDATE, DELETE
AS
BEGIN
DECLARE
@strAction varchar(10)

IF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted)
SET @strAction = 'insert'
 
IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
SET @strAction = 'update'
 
IF NOT EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
SET @strAction = 'delete'

declare @KEY_VALUE varchar(50);
IF @strAction = 'delete'
	select @KEY_VALUE=DJBH from deleted; 
ELSE
	select @KEY_VALUE=DJBH from inserted; 
insert into ONE_MTAB (KEY_VALUE,TAB_NAME,ACT_TYPE) values(@KEY_VALUE,'SPTHD',@strAction); 
END
GO